﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interfleet.SE.UICompiler.Core.YahooJavaScriptCompressor
{
    /// <summary>
    /// Argument buider for the Yahoo UI Compressor JavaScript.
    /// </summary>
    public class YJArgumentBuilder : ArgumentBuilder
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="arguments"><see cref="Arguments"/> for the compilation</param>
        public YJArgumentBuilder(Arguments arguments)
            : this(arguments, new FileProvider())
        { }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="arguments"><see cref="Arguments"/> for the compilation</param>
        /// <param name="fileProvider">An instance of <see cref="IFileProvider"/></param>
        public YJArgumentBuilder(Arguments arguments, IFileProvider fileProvider)
            : base(arguments, fileProvider, new YJCompileOptions())
        {}

        /// <summary>
        /// Builds up a string of all specified input files of the <see cref="Arguments"/>.
        /// </summary>
        /// <returns></returns>
        public override string Build()
        {
            var sb = new StringBuilder();
            foreach (var file in Arguments.Files)
            {
                sb.Append(FileProvider.ReadFileToEnd(file));
            }
            return sb.ToString();
        }
    }
}
